package com.aaa.stock.service.Impl;

import com.aaa.entity.*;
import com.aaa.stock.dao.ExamineDao;
import com.aaa.stock.dao.PurchaseDao;
import com.aaa.stock.dao.PurchaseItemDao;
import com.aaa.stock.feign.UserFeign;
import com.aaa.stock.service.ExamineService;
import com.aaa.stock.utils.IdWorker;
import com.aaa.stock.vo.ExamineVo;
import com.aaa.stock.vo.PurchaseDto;
import com.aaa.utils.JWTUtils;
import com.aaa.utils.WebUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;


@Service
public class ExamineServiceImpl  extends ServiceImpl<ExamineDao,Purchase> implements ExamineService{
    @Autowired
    private ExamineDao examineDao;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private PurchaseItemDao purchaseItemDao;

    @Override
    public Result<IPage<Purchase>> findBystatus(Integer currentPage, Integer pageSize, ExamineVo examineVo) {
        IPage<Purchase> page = new Page<>(currentPage, pageSize);
        QueryWrapper<Purchase> wrapper = new QueryWrapper<>();

        if (StringUtils.hasText(examineVo.getProviderId())) {
            wrapper.eq("provider_id", examineVo.getProviderId());
        }
        //状态
        if (StringUtils.hasText(examineVo.getApply_user_name())) {
            wrapper.eq("apply_user_name", examineVo.getApply_user_name());
        }

        wrapper.eq("status",2);
        IPage<Purchase> page1 = examineDao.selectPage(page, wrapper);
        return new Result<IPage<Purchase>>(200, "查询用户成功", page1);

    }

    //审核通过
    @Override
    public Result<Boolean> add(Purchase purchase) {
        purchase.setStatus("3");
        int i = examineDao.updateById(purchase);
        return new Result<>(200,"添加成功",i>0?true:false);
    }

    @Override
    public Result<Boolean> noadd(Purchase purchase) {
        purchase.setStatus("4");
        int i = examineDao.updateById(purchase);
        return new Result<>(200,"添加成功",i>0?true:false);
    }


    //查看详情
    @Override
    public Result quet(String purchaseId) {
        System.out.println("111111111111111111111111111111111111111="+purchaseId);
        QueryWrapper<PurchaseItem> queryWrapper=new QueryWrapper<>();
        if (StringUtils.hasText(purchaseId)){
            queryWrapper.eq("purchase_id",purchaseId);
        }
        System.out.println("0000000000000000000000000"+queryWrapper);
        List<PurchaseItem> items=purchaseItemDao.selectList(queryWrapper);
        System.out.println("======================================"+items);
        return new Result<>(200,"查询",items);
    }
}
